<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../publics/jstl.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title>运营管理平台-订单管理</title>
    <link href="${ctx}/resource/publics/jquery-easyui-1.4.4/themes/default/easyui.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/resource/publics/jquery-easyui-1.4.4/themes/icon.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="${ctx}/resource/publics/jquery-easyui-1.4.4/jquery.min.js"></script>
    <script type="text/javascript" src="${ctx}/resource/publics/jquery-easyui-1.4.4/jquery.easyui.min.js"></script>
    <script type="text/javascript">
        //修改模糊查询方式
        $.fn.combobox.defaults.filter = function(q, row){
            var opts = $(this).combobox('options');
            return row[opts.textField].indexOf(q) >= 0;
        }
    </script>
</head>
<body>
<table id="dg" title="" style="width:100%"></table>
<div id="tb" style="padding:2px 5px;">
    <a href="javascript:void(0)" onclick="updateMemberPoint()" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'">扣除积分</a>
    <a href="javascript:void(0)" onclick="editStatusWin()" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'">修改状态</a>
    <a href="javascript:void(0)" onclick="del()" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'">删除</a>
</div>
<div id="editStatusWin" class="easyui-window" title="修改状态" data-options="closed:true,inline:false,iconCls:'icon-edit'" style="width:100%;max-width:300px;padding:20px 0 10px 10px;">
    <div style="margin-bottom:20px">
        <form id="editStatusForm">
            <div style="margin-bottom:15px">
                <label>订单状态：</label>
                <select id="status" class="easyui-combobox" style="width:100px;">
                    <option value="0">处理中</option>
                    <option value="1">已完成</option>
                    <option value="2">已取消</option>
                </select>
                <label style="color: red">(*)</label>
            </div>
        </form>
    </div>
    <div style="text-align:center;padding:5px 0">
        <input id="edit-id" name="edit-id" type="hidden" value=""/>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="submitEditStatusWin()" style="width:80px">提交</a>
    </div>
</div>
<script type="text/javascript">
$('#dg').datagrid({
    title:'订单管理',
    border:false,
    fit:true,
    fitColumns:false,
    scrollbarSize:18,
    singleSelect:true,
    method:'post',
    url:'${ctx}/manage/order/getOrderList',
    idField:'id',
    toolbar:'#tb',
    pagination: true,
    pageSize: 20,
    rownumbers: true,
    columns:[[
        {field:'id',title:'订单ID',align:'center',width:50},
        {field:'userPhone',title:'客户手机',align:'center',width:75},
        {field:'userName',title:'客户姓名',align:'center',width:50},
        {field:'carName',title:'车辆名称',align:'center',width:70},
        {field:'carDescription',title:'车辆描述',align:'center',width:100},
        {field:'startCityName',title:'取车城市',align:'center',width:55},
        {field:'startShopName',title:'取车门店',align:'center',width:70},
        {field:'endCityName',title:'还车城市',align:'center',width:55},
        {field:'endShopName',title:'还车门店',align:'center',width:70},
        {field:'startDate',title:'取车日期',align:'center',width:70},
        {field:'endDate',title:'还车日期',align:'center',width:70},
        {field:'days',title:'天数',align:'center',width:50},
        {field:'price',title:'单价',align:'center',width:50},
        {field:'total',title:'总计',align:'center',width:50},
        {field:'status',title:'订单状态',align:'center',width:70,formatter: function(value,row,index){
            if (value == 0){
                return '处理中';
            } else if (value == 1) {
                return '已完成';
            } else if (value == 2) {
                return '已取消';
            }
        }},
        {field:'payStatus',title:'支付状态',align:'center',width:70,formatter: function(value,row,index){
            if (value == 0){
                return '未支付';
            } else if (value == 1) {
                return '已支付';
            }
        }},
        {field:'payType',title:'支付方式',align:'center',width:70,formatter: function(value,row,index){
            if (row.payStatus == 1) {
                if (value == 0){
                    return '微信';
                } else if (value == 1) {
                    return '支付宝';
                } else if (value == 2) {
                    return '储值支付';
                }
            } else {
                return "";
            }

        }},
        {field:'createTime',title:'订单时间',align:'center',width:130},
        {field:'openPointNo',title:'积分扣除单据',align:'center',width:130},
        {field:'totalSnapshot',title:'总价计算快照',align:'left',width:500}
    ]]
});
$('#dg').datagrid('getPager').pagination({
    pageSize: 20,
    pageList: [15, 20, 30],
    beforePageText: '第',
    afterPageText: '页    共 {pages} 页',
    displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
});
//修改订单状态
function editStatusWin() {
    var row = $('#dg').datagrid('getSelected');
    if (row) {
        $('#edit-id').val(row.id);
        $('#editStatusWin').window('open');
    } else {
        $.messager.alert('提示', '请先选中一行');
    }
}
//提交修改订单状态
function submitEditStatusWin() {
    var id = $('#edit-id').val();
    var status = $('#status').combobox('getValue');

    var paramz = {"id":id,"status":status};
    $.post('${ctx}/manage/order/updateOrderStatus', paramz, function(data, status){
        $.messager.alert('提示', data.msg);
        if (data.ret == 0) {
            $('#dg').datagrid('reload');
            $('#editStatusWin').window('close');
            $('#editStatusForm').form("reset");
        }
    }, 'json');
}
//删除记录
function del() {
    var row = $('#dg').datagrid('getSelected');
    if (row) {
        $.messager.confirm('提示', '确定删除吗?', function(r){
            if (r){
                var paramz = {"id":row.id};
                $.post('${ctx}/manage/order/deleteOrder', paramz, function(data, status){
                    if (data.ret == 0) {
                        $('#dg').datagrid('reload');
                    }
                }, 'json');
            }
        });
    } else {
        $.messager.alert('提示', '请先选中一行');
    }
}
//扣积分
function updateMemberPoint() {
    var row = $('#dg').datagrid('getSelected');
    if (row) {
        $.messager.confirm('提示', '确定扣除积分吗?', function(r){
            if (r){
                var paramz = {"id":row.id};
                $.post('${ctx}/manage/order/updateMemberPoint', paramz, function(data, status){
                    $.messager.alert('提示', data.msg);
                    if (data.ret == 0) {
                        $('#dg').datagrid('reload');
                    }
                }, 'json');
            }
        });
    } else {
        $.messager.alert('提示', '请先选中一行');
    }
}
</script>
</body>
</html>